import type { IResponseBody } from "@/common/Responsetypes";
import http from "./request";
import type { IPhotos, IUploadImg } from "@/common/JournalTypes";

/**
 * 发送注册的邮箱验证码
 * @param email
 * @returns
 */
export function sendEmailCode(email: string): Promise<IResponseBody<object>> {
  return http.post("/email/code", { email });
}

/**
 * 发送修改密码的邮箱验证码
 * @param email
 * @returns
 */
export function sendModifyPasswordEmailCode(
  email: string
): Promise<IResponseBody<object>> {
  return http.post("/email/modifyPassword/code", { email });
}

export function uploadJournalImg(
  files: IUploadImg[]
): Promise<IResponseBody<IPhotos[]>> {
  const newFiles = files.map((file) => {
    return {
      name: "files",
      uri: file.url,
      file: file.url as unknown as File,
    };
  });

  return http.upload("/upload/journal", {
    name: "files",
    files: newFiles,
  });
}
